package com.code.splider.controller;

import java.io.IOException;

import org.xml.sax.SAXException;

import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.HTMLElement;
import com.meterware.httpunit.HttpUnitOptions;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;

public class TestEX3 {

	 public static void main(String[] args) {  
	        try {  
	            //HttpunitTest.testGetHtmlContent();  
	            //HttpunitTest.testGetMethod();  
	            //HttpunitTest.testPostMethod();  
	        	TestEX3.testGetHtmlContent();  
	        } catch (Exception e) {  
	            e.printStackTrace();  
	        }  
	    }  
	      
	    public static void testGetHtmlContent() throws IOException, SAXException{  
	    	  System.out.println("直接获取网页内容：");  
	          // 建立一个WebConversation实例  
	          WebConversation wc = new WebConversation();  
	          // 向指定的URL发出请求，获取响应  
	          HttpUnitOptions.setExceptionsThrownOnScriptError(false);// js运行错误时，是否抛出异常
	          WebRequest req = new GetMethodWebRequest("http://www.dszuqiu.com/race_ls/238485");
	          // 用getText方法获取相应的全部内容  
	          // 用System.out.println将获取的内容打印在控制台上  
	          	WebResponse wr = wc.getResponse(req);  
	          // 用getText方法获取相应的全部内容  
	          // 用System.out.println将获取的内容打印在控制台上  
	          //System.out.println(wr.getText());  
	          WebLink s= wr.getLinkWithID("tabtypeid1");
	          s.click();
	          WebResponse nextLink = wc.getCurrentPage();
	          //System.out.println(nextLink.getElementsWithAttribute("id", "history_table"));
	          HTMLElement[]  t=  nextLink.getElementsWithAttribute("id", "history_table");
	          for (HTMLElement htmlElement : t) {
	        	  htmlElement.getTitle();
	        	  System.out.println(htmlElement.getText());
			}
	          //System.out.println(t);
	    }
	      
}
